﻿using System;
using System.Collections.Generic;
using System.IO;

namespace OpenWaves.EPiServer.AdminTools.LogViewer
{
    internal class NormalizedPathComparer : IEqualityComparer<string>
    {
        public bool Equals(string x, string y)
        {
            //before comparing normalized paths - compare input paths, to avoid normalizing
            return string.Equals(x, y, StringComparison.OrdinalIgnoreCase)
            || string.Equals(GetNormalizedPath(x), GetNormalizedPath(y), StringComparison.Ordinal);
        }

        public int GetHashCode(string obj)
        {
            return GetNormalizedPath(obj).GetHashCode();
        }

        private static string GetNormalizedPath(string s)
        {
            return s == null
                       ? null
                       : Path.GetFullPath(s).ToUpperInvariant();
        }
    }
}